/*
 * Copyright (c) 2011  Cristian Constantin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.quizio.engine.model;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author Cristian Constantin
 * @since 10/24/11
 */
@Entity
@Table(name = "question_user_inputs")
public class QuestionUserInput implements Serializable {

    private Long id;

    @JsonIgnore
    private QuizSession quizSession;

    private Question question;

    private String answer;

    /**
     * The score obtained by the user on a scale from 0 to 100.
     * It is computed automatically after the user submits the quiz.
     */
    private Long score;

    public QuestionUserInput() {
    }

    public QuestionUserInput(Question question, QuizSession quizSession) {
        this.question = question;
        this.quizSession = quizSession;
    }

    @Id
    @SequenceGenerator(name = "question_user_inputs_pk_sequence", sequenceName = "question_user_inputs_id_seq")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "question_user_inputs_pk_sequence")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne
    public QuizSession getQuizSession() {
        return quizSession;
    }

    public void setQuizSession(QuizSession quizSession) {
        this.quizSession = quizSession;
    }

    @ManyToOne
    public Question getQuestion() {
        return question;
    }

    public void setQuestion(Question question) {
        this.question = question;
    }

    @Column
    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Column
    public Long getScore() {
        return score;
    }

    public void setScore(Long score) {
        this.score = score;
    }
}
